﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;
using System.Web.UI;

namespace AVO.Layouts
{
    public class AVOPageBase : LayoutsPageBase
    {
        protected string strContentTypeID = string.Empty;
        protected string strListId = string.Empty;

        protected ContentTypeConfiguration this[SPContentTypeId ctid]
        {
            get
            {
                SPContentType tmpCT = GetContentType(ctid, SPContext.Current.ListId);
                var retCfg = new ContentTypeConfiguration(tmpCT);
                retCfg.Load(true);
                return retCfg;
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            strContentTypeID = this.Request.QueryString["ctype"];
            strListId = this.Request.QueryString["List"];

            base.OnLoad(e);
        }

        private SPContentType GetContentType(SPContentTypeId id, Guid listId)
        {
            if (!Guid.Empty.Equals(listId))
            {
                var list = SPContext.Current.Web.Lists[listId];
                return list.ContentTypes[id];
            }

            return SPContext.Current.Web.ContentTypes[id];
        }
    }
}
